#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	string name,id,maxname,maxid,minname,minid;
	int maxsc=-1,minsc=101,sc;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>name>>id>>sc;
		if(sc>maxsc){
			maxsc=sc;
			maxname=name;
			maxid=id;
		}
		if(sc<minsc){
			minsc=sc;
			minname=name;
			minid=id;
		}
	}
	cout<<maxname<<" "<<maxid<<endl;
	cout<<minname<<" "<<minid;
	return 0;
}
